package com.heima.controller;

import com.heima.pojo.dto.CommodityPageQueryDTO;
import com.heima.pojo.vo.CommodityVO;
import com.heima.pojo.dto.CommodityDTO;
import com.heima.pojo.vo.PageSearchQueryVO;
import com.heima.service.CommodityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;

@RestController
@Slf4j
@RequestMapping("/api/vm-service/skuClass")
@Api(tags = "商品分类管理模块")
public class CommodityController {

    @Autowired
    CommodityService commodityService;

/**
 * 商品分类
 **/
@ApiOperation("商品分类")
@PostMapping
public boolean Sort(@RequestBody CommodityDTO dto) {
    commodityService.addSort(dto);
    return true;
}
/**
 * 分页查询
 **/
@GetMapping("/search")
@ApiOperation("分页查询")
public PageSearchQueryVO pagingQuery(CommodityPageQueryDTO dto){
    PageSearchQueryVO pageSearchQueryVO  =  commodityService.pagingQuery(dto);
        return pageSearchQueryVO;
}
/**
 *根据id查询分类数据
 * **/
    @GetMapping("/{classId}")
    @ApiOperation("根据id查询分类数据")
    public CommodityVO getId(@PathVariable Integer classId){
        CommodityVO vo = commodityService.getId(classId);
        return vo;
}
    /**
    * 修改分类数据
    * **/
    @ApiOperation("修改分类数据")
    @PutMapping("/{classId}")
        public boolean update(@RequestBody CommodityDTO dto,@PathVariable Integer classId){
        //运行中找不到classNme，单独拿出来
        String className = dto.getClassName();
        commodityService.update(className,classId);
        return true;
    }
    /**
    * 根据id删除分类
    * **/
    @DeleteMapping("/{classId}")
    @ApiOperation("根据id删除分类")
    public Boolean deldeteId(@PathVariable("classId") Integer classId){
        commodityService.deleteId(classId);
        return true;
    }
}
